﻿using EmitDebugging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Spackle.Testing;
using System;
using System.Runtime.InteropServices;

namespace EmitDebugging.Tests
{
	[TestClass]
	public sealed class UnmanagedCalliDescriptorTests : CoreTests
	{
		[TestMethod]
		public void GetDescription()
		{
			Assert.AreEqual("unmanaged stdcall int32(uint8, valuetype System.Guid)",
				new UnmanagedCalliDescriptor(CallingConvention.StdCall, typeof(int),
					new Type[] { typeof(byte), typeof(Guid) }).Value);
		}

		[TestMethod]
		public void GetDescriptionWithNoArguments()
		{
			Assert.AreEqual("unmanaged stdcall int32()",
				new UnmanagedCalliDescriptor(CallingConvention.StdCall, typeof(int),
					Type.EmptyTypes).Value);
		}

		[TestMethod]
		public void GetDescriptionWithNullArguments()
		{
			Assert.AreEqual("unmanaged stdcall int32()",
				new UnmanagedCalliDescriptor(CallingConvention.StdCall, typeof(int),
					null).Value);
		}

		[TestMethod]
		public void GetDescriptionWithNullReturn()
		{
			Assert.AreEqual("unmanaged stdcall void(uint8, valuetype System.Guid)",
				new UnmanagedCalliDescriptor(CallingConvention.StdCall, null,
					new Type[] { typeof(byte), typeof(Guid) }).Value);
		}

		[TestMethod]
		public void GetDescriptionWithVoidReturn()
		{
			Assert.AreEqual("unmanaged stdcall void(uint8, valuetype System.Guid)",
				new UnmanagedCalliDescriptor(CallingConvention.StdCall, typeof(void),
					new Type[] { typeof(byte), typeof(Guid) }).Value);
		}
	}
}
